import axios from "axios";
import { showToast } from "vant";

const instance = axios.create({
  baseURL: import.meta.env.VITE_BASE_URL,
  timeout: 30000,
});

instance.interceptors.response.use(
  async (response) => {
    const { status, statusText, data } = response;

    if (status === 200) {
      return data;
    } else if (status === 204) {
      showToast(statusText || "系统异常");
    }
    return Promise.reject(response);
  },
  (err) => Promise.reject(err)
);

export default instance;
